const fs = require('fs');
const { send } = require('process');
const axios = require('axios')

const filePath = 'C:\\Users\\18330\\Documents\\lhdl\\10\\指标汇聚\\端节点指标上报\\'

const fileNameArr = ['nodeInfo', 'segment', 'makeOrder', 'writeBusiness', 'writeResource']


function sendAll() {
    customConfig = {
        headers: {
            'Content-Type': 'application/json',
            'reportTime': '20230216181700'
        }
    };
    fileNameArr.forEach(x => {
        let finalFilePath = `${filePath}${x}.txt`;
        fs.readFile(finalFilePath, 'UTF-8', async (err, data) => {
            if(err) {
                console.log('read file error: ', finalFilePath);
                return;
            }
            // if (x === 'nodeInfo') {
            //     console.log('data: ', data)
            // }
            await axios.post('http://localhost:8080/metrics/report', data, customConfig);
            console.log('send finalFilePath: ', finalFilePath)
        })
    })
    console.log('send end...')
}

sendAll();